<?php

namespace App\Admin\Controllers\Note;

use App\Admin\Controllers\Traits\WxNoteTraits\formNoteTrait;
use Dcat\Admin\Widgets\Form;

class WxNoteController extends Form
{
    use formNoteTrait;

    protected $options = [
        0 => '是',
        1 => '否',
    ];

    protected $audit_options = [
        0 => '人工审核',
        1 => '不审',
        2 => 'AI先审，若疑似，则人工'
    ];

    public function handle(array $input)
    {
        // $input是你接收到的表单数据
        // 在这里可以写你的处理逻辑
        // 第一个参数是响应的成功信息，第二个参数是要跳转的路由
        return $this->response()->success('Processed successfully.')->refresh();
    }

    public function _table_keyvalue_data(array $data){
        if(_empty_($data)){
            return json_encode([]);
        }
        $_data = [];
        foreach ($data as $row){
            if(_array_key($row, '_remove_', null) == 1){
                continue;
            }
            if(isset($row['_remove_'])){
                unset($row['_remove_']);
            }
            if(!is_array($row)) {
                $_data[] = $row;
                continue;
            }
            $row_ = [];
            foreach ($row as $key => $value){
                if(!is_array($value)){
                    $row_[$key] = $value;
                    continue;
                }
                unset($value['_def_']);
                if(!isset($value['keys']) && !isset($value['values'])){
                    $row_[$key] = $value;
                    continue;
                }
                $_value = [];
                if(isset($value['keys'][0])){
                    for($i = 0; $i < count($value['keys']); $i ++){
                        $_value[$value['keys'][$i]] = $value['values'][$i];
                    }
                }else{
                    for($i = 1; $i <= count($value['keys']); $i ++){
                        $_value[$value['keys'][$i]] = $value['values'][$i];
                    }
                }
                $row_[$key] = $_value;
            }
            $_data[] = $row_;
        }
        return json_encode($_data);
    }
}
